<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<!--引入vue-->
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<div id="app">
  <cpn></cpn>
</div>
<template id="cpn">
  <div>
    <h2>我是cpn</h2>
    <ccpn></ccpn>
  </div>
</template>
<template id="ccpn">
  <div>
    <h2>我是ccpn</h2>
    <button @click="btnClick">按钮</button>
  </div>
</template>
<script>
  const app = new Vue({
    el: "#app",
    data:{
      message:"Hello zk I am Vue !"
    },
    components:{
      cpn:{
        template:'#cpn',
        data(){
          return{
            name:'我是cpn组件的name'
          }
        },
        components:{
          ccpn:{
            template: '#ccpn',
            methods:{
              btnClick() {

                console.log(this.$parent);
                console.log(this.$parent.name);

                console.log(this.$root);
                console.log(this.$root.message);
              }
            },
          },
        }
      }
    }
  })
</script>
</body>
</html>
